let parentId = 0
$(function () {
    $("#gradeTable").bootstrapTable({
        method: "get",
        contentType: "application/json",
        url: "/inputmanagerController/getsPaycheck_tag0",
        // striped: true,
        pageNumber: 1,
        pagination: true,
        sidePagination: 'server',
        pageSize: 5,
        pageList: [1, 3, 5, 7],
        queryParams: function (parmes) {
            return {
                pageNum: (parmes.offset / parmes.limit) + 1,
                pageSize: parmes.limit,
                storer: $("#storer").val(),
                payId: $("#gatherId").val(),
                registerTime: $("#registerTime").val(),
                checker: $("#checker").val()
            }
        },
        columns: [
            { title: "申请单编号", field: 'payId', align: "center" },
            { title: "出库理由", field: 'reason', align: "center" },
            { title: "登记时间", field: 'registerTime', align: "center" },
            { title: "总计数", field: 'amountSum', align: "center" },
            { title: "总金额", field: 'costPriceSum', align: "center" },
            {
                title: "审核", field: 'payId', align: "center",
                formatter: function (value,row,index) {
                    var btn1 = "<button class=\"btn btn-success btn-sm\" onclick='checkTag("+value+","+JSON.stringify(row)+")'>审核</button>";
                    return btn1
                }
            }
        ]
    })
    $("#condition").click(function(){
        $("#gradeTable").bootstrapTable("refresh")
    })
})
//审核  跳页面 把该出库单 和明细显示出来
function checkTag(gatherId,parse) {
    console.log(parse)
    $("#two").show()
    $("#one").hide()
    $("#rkr").val(parse.storer)
    $("#rkly").val(parse.reason)
    $("#zjs").html(parse.amountSum)
    $("#zje").html(parse.costPriceSum)
    $("#djr").html(parse.register)
    $("#djsj").html(parse.registerTime)
    $("#bz").val(parse.remark)
    parentId=parse.id
    $.ajax({
        url:"/inputmanagerController/BySpayIdqueryspayDetails",
        type:"get",
        contentType: "application/json",
        async:true,
        data:{
            id:parse.id,
        },
        success:function (list) {
            console.log(list)
            let content="";
            for (let i = 0; i < list.length; i++) {
                if(list[i].amountUnit==undefined){
                    list[i].amountUnit=""
                }
                content += "<tr>" +
                    "<td>" + list[i].productName + "</td>" +
                    "<td>" + list[i].productId + "</td>" +
                    "<td>" + list[i].productDescribe + "</td>" +
                    "<td>" + list[i].amount + "</td>" +
                    "<td>" + list[i].amountUnit + "</td>" +
                    "<td>" + list[i].costPrice + "</td>" +
                    "<td>" + list[i].subtotal + "</td>" +
                    "</tr>"
            }
            $("#tbody").append(content)
        }
    })
}
//审核通过与不通过
function pass(checkTag) {
    if(confirm("确定提交吗")) {
        $.ajax({
            url: "/inputmanagerController/updateSPaycheckTag",
            type: "get",
            contentType: "application/json",
            async: true,
            data: {
                id: parentId,
                checkTag: checkTag
            },
            success: function (data) {
                parent.document.getElementById('iframeId').contentWindow.location.reload(true);
            }
        })
    }
}

function demand() {
    $("#gradeTable").bootstrapTable("refresh")
}
function fh() {
    $("#one").show()
    $("#two").hide()
}